package cn.getech.data.development.utils.sched;

import cn.getech.data.development.service.CountTableRowsNumService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

/***
 * 统计表分区信息
 */
@Slf4j
@Configuration
//@EnableScheduling
//@ConditionalOnProperty(name = "data-development.table-statistics-open", havingValue = "true")
public class TableStatisticsTask {

    @Autowired
    private CountTableRowsNumService countTableRowsNumService;

    @Autowired
    private TablePartitionStatisticsTask tablePartitionStatisticsTask;

    public void startTask(){
        tableRowsNumStatisticsTask();
    }

//    @Scheduled(cron = "0 05 8 * * ?")
    public void tableRowsNumStatisticsTask() {
        try {
            countTableRowsNumService.postCountTableRowsNum();
        }catch (Exception e){
            log.error("统计表信息出错：", e);
        }
    }

//    @Scheduled(cron = "0 5 9 * * ?") // 0 0 5 * * ?
    public void tablePartitionStatiticsTask(String day) {
        tablePartitionStatisticsTask.tablePartitionStatiticsTask(day);
    }
}
